#!/bin/bash 


# ga_update        Startup script for get xenserver vm status
#
# chkconfig: - 85 15
# description: get vm status every 5 min.
# processname: ga_update



PIDFILE=/var/run/ga_update.pid
COMMAND="/usr/bin/python /root/cs-bs/xen_api/update_ga.py &"
service_name="update_ga"
 
# Source function library
. /etc/rc.d/init.d/functions
 
 
start() {
        echo -n "Starting My Daemon: "
        if [ -f $PIDFILE ]; then
                PID=`cat $PIDFILE`
                echo update ga is not  running: $PID
                exit 2;
    	fi 
        daemon $COMMAND
	echo $(ps x | grep $service_name | grep -v grep| awk -F " " '{print $1}') >  $PIDFILE 
    echo
}
 
stop(){
	if [ ! -f $PIDFILE ]; then
                echo udpate ga  is not running
                exit 1;
        fi

        echo -n "Stopping My Daemon: "
	daemon $(kill -9 $(cat $PIDFILE) && rm -f $PIDFILE)
    echo
}
status() {
        echo -n "Starting update_ga: "
	if [ -f $PIDFILE ]; then
                PID=`cat $PIDFILE`
                echo udpate ga already running: $PID
                exit 0;
	else 
		echo udpate ga is not  running
        fi
	
}
 
case "$1" in
  start)
    start
        ;;
  stop)
    stop
        ;;
  restart)
        stop
    start
        ;;
  status)
        status 
        ;;
  *)
        echo "Usage: {start|stop|restart|status}"
        exit 1
esac
 
exit 0
